// pages/server_end/apply_server/apply_server.js
const app = getApp();
const request = require('../../../utils/request.js');
const url = require('../../../utils/url.js');
const cookie = require('../../../utils/cookie.js');

const WxParse = require('../../../wxParse/wxParse.js');

Page({

    /**
     * 页面的初始数据
     */
    data: {
        contact_name: "",
        contact_tel: "",
        postcode: "",
        addr: "",
        addr_detail: "",
        sevice_category_id: [],
        desc: "",
        setlocation: 0,
        lat: 0,
        lng: 0,
        uploadfront: 0,
        uploadback: 0,
        idcard_front_image: "",
        idcard_front_image_url: "/static/icon/icon_upload_id1.png",
        idcard_back_image: "",
        idcard_back_image_url: "/static/icon/icon_upload_id2.png",
        regionValue: '',
        serverType: "",
        serverTypeRange: [],
        categorylist: [],
        servicetaglist: [],
        taglist: [],
		 yftaglist: [],
		 yftag:'默认',
		 mjtaglist: [],
		 mjtag:'默认',
		  kztag:'默认',
		  servicemjlist: [
			  {
				  name:'S',
				  active:0
			  },{
				  name:'M',
				  active:0
			  },{
				  name:'L',
				  active:0
			  },{
				  name:'XL',
				  active:0
			  },{
				  name:'XXL',
				  active:0
			  },{
                name:'XXXL',
                active:0
            },
		  ],
		  servicekzlist: [
		  			  {
		  				  name:'S',
		  				  active:0
		  			  },{
		  				  name:'M',
		  				  active:0
		  			  },{
		  				  name:'L',
		  				  active:0
		  			  },{
		  				  name:'XL',
		  				  active:0
		  			  },{
		  				  name:'XXL',
		  				  active:0
		  			  },{
                        name:'XXXL',
                        active:0
                    },
		  ],
        tagIds: [],
        imgs: [],
        picList: [],
        imgss: [],
        picLists: [],
        token: "",
        show: 0,
        show1: false,
        show2: false,
		show3: false,
		show4: false,
        deposit: '',
        agreement:true,
		 countdown: 5,
		 buttonDisabled:true,
		 cityName:''
    },
    closeTime2() {
        this.setData({
            show2: false
        })
    },
    closeTime1() {
        this.setData({
            show1: false
        })
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        //获取标签信息
        this.getServiceTag();
        this.getServiceType();
        this.getDepositMoney();
        //this.getAgreement();
		
        var that = this;
        wx.request({
          url: 'https://mcc.huotukj.com/index.php/api/xiservice.service_category/checkincontract',
          data: {},
          header: {
            'content-type': 'application/json' // 默认值
          },
          success: function (res) {

           let content = res.data.data.content;
           console.log(content);
           WxParse.wxParse('htcontent', 'html', content, that, 0)
          }
        })
		// that.data.countdownInterval = setInterval(that.countdownTimer, 1000);
		that.countdownTimer();
    },
 countdownTimer: function() {
   const that = this;
   let countdown = that.data.countdown;  
   // 设置定时器
   let timer = setInterval(function() {
     countdown--;	    
 	that.setData({
 	  countdown: countdown
 	});
 	console.log(that.data.countdown);
     // 当倒计时结束时
     if (countdown <= 0) {
       clearInterval(timer);
      that.setData({
        countdown: 0,
        buttonDisabled: false
      });
     }
   }, 1000);  
   
  
 },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {
            
      

    },
    // async getAgreement(){
    //     let param = {
    //       scoure: 'wxapp',
    //       token: that.data.token
    //   }
    // },
        // const res = await request.request(url.agreement,param,url.REQUEST_METHOD_GET);
 
//   console.log(res);

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {
        var that = this;
        cookie.getCookie('userInfo', function (res) {
            if (res) {
                var etime = Date.parse(new Date()) / 1000;

                if (etime < res.expiretime) {
                    that.setData({
                        login: 1,
                        token: res.token
                    })
                }
            }
        })
    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    changeAgreement(){
        this.setData({
            agreement:false
        })
    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    },
    changecontactname(e) {
        this.setData({
            contact_name: e.detail.value
        })
    },
    changecontacttel(e) {
        this.setData({
            contact_tel: e.detail.value
        })
    },
    changeaddr(e) {
        this.setData({
            addr_detail: e.detail.value
        })
    },
    changedesc(e) {
        this.setData({
            desc: e.detail.value
        })
    },
    getServiceTag() {
        var that = this;
        let param = {
            scoure: 'wxapp',
            token: that.data.token
        }
        wx.showNavigationBarLoading(); //在当前页面显示导航条加载动画
        request.request(url.taglist, param, url.REQUEST_METHOD_GET).then((res) => {
            wx.hideNavigationBarLoading(); //在当前页面隐藏导航条加载动画
            if (res.data.code == 1) {
                that.setData({
                    servicetaglist: res.data.data
                })
            }
        })
    },
    getServiceType() {
        var that = this;
		var cityName = wx.getStorageSync('cityName');
        let param = {
            scoure: 'wxapp',
            token: that.data.token,
			cityName:cityName
        }
        wx.showNavigationBarLoading(); //在当前页面显示导航条加载动画
        request.request(url.secondcategorylist, param, url.REQUEST_METHOD_GET).then((res) => {
            wx.hideNavigationBarLoading(); //在当前页面隐藏导航条加载动画
            if (res.data.code == 1) {
                that.setData({
                    serverTypeRange: res.data.data,
                    categorylist: res.data.data
                })
            }
        })
    },
    getDepositMoney() {
        var that = this;
        let param = {
            scoure: 'wxapp',
            token: that.data.token
        }
        wx.showNavigationBarLoading(); //在当前页面显示导航条加载动画
        request.request(url.getdepositmoney, param, url.REQUEST_METHOD_GET).then((res) => {
            wx.hideNavigationBarLoading(); //在当前页面隐藏导航条加载动画
            if (res.data.code == 1) {
                that.setData({
                    deposit: res.data.data
                })
            }
        })
    },
    getWorkerInfo: function () {
        var that = this;
        let param = {
            scoure: 'wxapp',
            token: that.data.token
        }
        wx.showNavigationBarLoading(); //在当前页面显示导航条加载动画
        request.request(url.workerinfo, param, url.REQUEST_METHOD_GET).then((res) => {
            wx.hideNavigationBarLoading(); //在当前页面隐藏导航条加载动画
            if (res.data.code == 1) {
                that.setData({
                    contact_name: res.data.data.contact_name,
                    contact_tel: res.data.data.contact_tel,
                    addr: res.data.data.addr,
                    addr_detail: res.data.data.addr_detail,
                    service_tag_ids: res.data.data.service_tag_ids,
                    desc: res.data.data.desc,
                    setlocation: 1,
                    taglist: res.data.data.tag,
                    lat: res.data.data.lat,
                    lng: res.data.data.lng,
                    picList: res.data.data.extra_image_arr,
                    imgs: res.data.data.extra_image_arr_url,
                    
                    picLists: res.data.data.extra_image_arr,
                    imgss: res.data.data.extra_image_arr_url,
                })
            }
        })
    },
    showtag() {
        this.setData({
            show1: true
        })
    },
	showyfsize() {
	    this.setData({
			serviceyflist: [
						  {
							  name:'S',
							  active:0
						  },{
							  name:'M',
							  active:0
						  },{
							  name:'L',
							  active:0
						  },{
							  name:'XL',
							  active:0
						  },{
							  name:'XXL',
							  active:0
						  },{
                            name:'XXXL',
                            active:0
                        },
			],
	        show3: true
			
	    })
	},
	showmjsize() {
	    this.setData({
			servicemjlist: [
						  {
						  	name:'XS',
						  	 active:0
						  },{
							  name:'S',
							  active:0
						  },{
							  name:'M',
							  active:0
						  },{
							  name:'L',
							  active:0
						  },{
							  name:'XL',
							  active:0
						  },{
							  name:'2XL',
							  active:0
						  },{
							  name:'3XL',
							  active:0
						  },{
	                        name:'4XL',
	                        active:0
	                    },
			],
	        show5: true
			
	    })
	},
	showkzsize() {
	    this.setData({
			serviceykzist: [
						  {
							  name:'S',
							  active:0
						  },{
							  name:'M',
							  active:0
						  },{
							  name:'L',
							  active:0
						  },{
							  name:'XL',
							  active:0
						  },{
							  name:'XXL',
							  active:0
						  },{
                            name:'XXXL',
                            active:0
                        },
			],
	        show4: true
	    })
	},
    closeTime() {
        this.setData({
            show1: false
        })
    },
    open1() {
        this.setData({
            show2: true
        })
    },
    closeTime2() {
        this.setData({
            show1: false,
            show2: false
        })
    },
    choseTag(e) {
        var that = this;
        var id = e.currentTarget.dataset.id;
        that.data.servicetaglist.forEach((item, index) => {
            console.log(item.id);
            if (item.id == id) {
                if (item.active == 1) {
                    var active = 0;
                } else {
                    var active = 1;
                }
                var sItem = 'servicetaglist[' + index + '].active';
                this.setData({
                    [sItem]: active
                })
            }
        });
        var array = [];
        var arrayIds = [];
        that.data.servicetaglist.forEach((item, index) => {
            if (item.active == 1) {
                array.push(that.data.servicetaglist[index]);
                arrayIds.push(that.data.servicetaglist[index].id);
            }
        })
        that.setData({
            taglist: array,
            tagIds: arrayIds
        })
    },
	choseyfTag(e) {
	    var that = this;
	    var id = e.currentTarget.dataset.id;
		console.log('id:'+id)
	    that.data.serviceyflist.forEach((item, index) => {
	        console.log(item.name);
	        if (item.name == id) {
	            if (item.active == 1) {
	                var active = 0;
	            } else {
	                var active = 1;
	            }
	            var sItem = 'serviceyflist[' + index + '].active';
	            this.setData({
	                [sItem]: active
	            })
	        }
	    });
		var yftag='';
	    that.data.serviceyflist.forEach((item, index) => {
	        if (item.active == 1) {
				yftag = that.data.serviceyflist[index];
	            // arrayIds.push(that.data.servicetaglist[index].id);
	        }
	    })
	    that.setData({
			yftag:yftag.name,
			show3:false
	        // tagIds: arrayIds
	    })
	},
	chosemjTag(e) {
	    var that = this;
	    var id = e.currentTarget.dataset.id;
		console.log('id:'+id)
	    that.data.servicemjlist.forEach((item, index) => {
	        console.log(item.name);
	        if (item.name == id) {
	            if (item.active == 1) {
	                var active = 0;
	            } else {
	                var active = 1;
	            }
	            var sItem = 'servicemjlist[' + index + '].active';
	            this.setData({
	                [sItem]: active
	            })
	        }
	    });
		var mjtag='';
	    that.data.servicemjlist.forEach((item, index) => {
	        if (item.active == 1) {
				mjtag = that.data.servicemjlist[index];
	            // arrayIds.push(that.data.servicetaglist[index].id);
	        }
	    })
	    that.setData({
			mjtag:mjtag.name,
			show5:false
	        // tagIds: arrayIds
	    })
	},
	chosekzTag(e) {
	    var that = this;
	    var id = e.currentTarget.dataset.id;
		console.log('id:'+id)
	    that.data.servicekzlist.forEach((item, index) => {
	        console.log(item.name);
	        if (item.name == id) {
	            if (item.active == 1) {
	                var active = 0;
	            } else {
	                var active = 1;
	            }
	            var sItem = 'servicekzlist[' + index + '].active';
	            this.setData({
	                [sItem]: active
	            })
	        }
	    });
		var kztag='';
	    that.data.servicekzlist.forEach((item, index) => {
	        if (item.active == 1) {
				kztag = that.data.servicekzlist[index];
	            // arrayIds.push(that.data.servicetaglist[index].id);
	        }
	    })
	    that.setData({
			kztag:kztag.name,
			show4:false
	        // tagIds: arrayIds
	    })
	},
    regionChange(e) {
        console.log('picker发送选择改变，携带值为', e.detail)
        this.setData({
            postcode: e.detail.postcode,
            regionValue: e.detail.value
        })
    },
    choselocation() {
        var that = this;
        console.log('wxchoseLocation');
        wx.chooseLocation({
            success: function (res) {
                console.log("地图点击事件：" + JSON.stringify(res));
                that.setData({
                    addr: res.address,
                    lat: res.latitude,
                    lng: res.longitude,
                    setlocation: 1
                });

            }
        })
    },
    // 删除图片
    deleteImg: function (e) {
        var imgs = this.data.imgs;
        var picList = this.data.picList;
        var index = e.currentTarget.dataset.index;
        imgs.splice(index, 1);
        picList.splice(index, 1);
        this.setData({
            imgs: imgs,
            picList: picList
        });
        console.log(picList);
    },
    chooseImg: function (e) {
        var that = this;
        var imgs = this.data.imgs;
        if (imgs.length >= 3) {
            this.setData({
                lenMore: 1
            });
            setTimeout(function () {
                that.setData({
                    lenMore: 0
                });
            }, 2500);
            return false;
        }
        var count = 3 - imgs.length;
        if (count < 1) {
            return false;
        }

        wx.chooseImage({
            count: count, // 默认9
            sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图，默认二者都有
            sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机，默认二者都有
            success: function (res) {
                // 返回选定照片的本地文件路径列表，tempFilePath可以作为img标签的src属性显示图片
                if (res.errMsg == "chooseImage:ok") {
                    wx.showLoading({ //显示loding提示框
                        title: '正在上传中...',
                    })
                    let picList = that.data.picList
                    var imgs = that.data.imgs;
                    res.tempFilePaths.forEach((item, index) => {
                        imgs.push(item)
                        that.setData({
                            imgs: imgs,
                        });
                        wx.uploadFile({
                            url: url.HttpServerHostAddress + url.uploadpic,
                            filePath: item,
                            name: 'file',
                            formData: {
                                token: that.data.token
                            },
                            success: function (res) {
                                let ress = JSON.parse(res.data)
                                if (ress.code == 1) {
                                    var picList = that.data.picList;
                                    picList.push(JSON.parse(res.data).data.url);
                                    that.setData({
                                        picList: picList,
                                    })
                                    console.log(picList);
                                } else {
                                    wx.showToast({
                                        title: JSON.parse(res.data).msg,
                                        icon: 'none',
                                        duration: 3000
                                    })
                                    return;
                                }
                            },
                            fail: res => {
                                console.log(res)
                            }
                        })
                    })
                    wx.hideLoading(); //隐藏loading提示框
                }
            }
        });
    },

    deleteImgs: function (e) {
        var imgs = this.data.imgss;
        var picList = this.data.picLists;
        var index = e.currentTarget.dataset.index;
        imgs.splice(index, 1);
        picList.splice(index, 1);
        this.setData({
            imgss: imgs,
            picLists: picList
        });
        console.log(picList);
    },
    chooseImgs: function (e) {
        var that = this;
        var imgs = this.data.imgss;
        if (imgs.length >= 4) {
            this.setData({
                lenMore: 1
            });
            setTimeout(function () {
                that.setData({
                    lenMore: 0
                });
            }, 2500);
            return false;
        }
        var count = 4 - imgs.length;
        if (count < 1) {
            return false;
        }

        wx.chooseImage({
            count: count, // 默认9
            sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图，默认二者都有
            sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机，默认二者都有
            success: function (res) {
                // 返回选定照片的本地文件路径列表，tempFilePath可以作为img标签的src属性显示图片
                if (res.errMsg == "chooseImage:ok") {
                    wx.showLoading({ //显示loding提示框
                        title: '正在上传中...',
                    })
                    let picList = that.data.picLists
                    var imgs = that.data.imgss;
                    res.tempFilePaths.forEach((item, index) => {
                        imgs.push(item)
                        that.setData({
                            imgss: imgs,
                        });
                        wx.uploadFile({
                            url: url.HttpServerHostAddress + url.uploadpic,
                            filePath: item,
                            name: 'file',
                            formData: {
                                token: that.data.token
                            },
                            success: function (res) {
                                let ress = JSON.parse(res.data)
                                if (ress.code == 1) {
                                    var picList = that.data.picLists;
                                    picList.push(JSON.parse(res.data).data.url);
                                    that.setData({
                                        picLists: picList,
                                    })
                                    console.log(picList);
                                } else {
                                    wx.showToast({
                                        title: JSON.parse(res.data).msg,
                                        icon: 'none',
                                        duration: 3000
                                    })
                                    return;
                                }
                            },
                            fail: res => {
                                console.log(res)
                            }
                        })
                    })
                    wx.hideLoading(); //隐藏loading提示框
                }
            }
        });
    },
    choseType(e) {
        var that = this;
        var id = e.currentTarget.dataset.id;
        that.data.categorylist.forEach((item, index) => {
            if (item.id == id) {
                if (item.active == 1) {
                    var active = 0;
                } else {
                    var active = 1;
                }
                var sItem = 'categorylist[' + index + '].active';
                that.setData({
                    [sItem]: active
                })
            }
        });
        var array = [];
        var arrayIds = [];
        that.data.categorylist.forEach((item, index) => {
            if (item.active == 1) {
                array.push(that.data.categorylist[index].name);
                arrayIds.push(that.data.categorylist[index].id);
            }
        })

        that.setData({
            serverType: array,
            sevice_category_id: arrayIds
        })
    },
    uploadidcardImage(e) {
        var type = e.currentTarget.dataset.type;
        var that = this;
        wx.chooseImage({
            count: 1, // 默认9
            sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图，默认二者都有
            sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机，默认二者都有
            success: function (res) {
                // 返回选定照片的本地文件路径列表，tempFilePath可以作为img标签的src属性显示图片
                if (res.errMsg == "chooseImage:ok") {
                    wx.showLoading({ //显示loding提示框
                        title: '正在上传中...',
                    })
                    res.tempFilePaths.forEach((item, index) => {

                        wx.uploadFile({
                            url: url.HttpServerHostAddress + url.uploadpic,
                            filePath: item,
                            name: 'file',
                            formData: {
                                token: that.data.token
                            },
                            success: function (res) {
                                let ress = JSON.parse(res.data)
                                if (ress.code == 1) {
                                    if (type == 1) {
                                        that.setData({
                                            uploadfront: 1,
                                            idcard_front_image: JSON.parse(res.data).data.url,
                                            idcard_front_image_url: JSON.parse(res.data).data.fullurl
                                        })
                                    } else {
                                        that.setData({
                                            uploadback: 1,
                                            idcard_back_image: JSON.parse(res.data).data.url,
                                            idcard_back_image_url: JSON.parse(res.data).data.fullurl
                                        })
                                    }
                                } else {
                                    wx.showToast({
                                        title: JSON.parse(res.data).msg,
                                        icon: 'none',
                                        duration: 3000
                                    })
                                    return;
                                }
                            },
                            fail: res => {
                                console.log(res)
                            }
                        })
                    })
                    wx.hideLoading(); //隐藏loading提示框
                }
            }
        });
        wx.chooseImages({
            count: 1, // 默认9
            sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图，默认二者都有
            sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机，默认二者都有
            success: function (res) {
                // 返回选定照片的本地文件路径列表，tempFilePath可以作为img标签的src属性显示图片
                if (res.errMsg == "chooseImage:ok") {
                    wx.showLoading({ //显示loding提示框
                        title: '正在上传中...',
                    })
                    res.tempFilePaths.forEach((item, index) => {

                        wx.uploadFile({
                            url: url.HttpServerHostAddress + url.uploadpic,
                            filePath: item,
                            name: 'file',
                            formData: {
                                token: that.data.token
                            },
                            success: function (res) {
                                let ress = JSON.parse(res.data)
                                if (ress.code == 1) {
                                    if (type == 1) {
                                        that.setData({
                                            uploadfront: 1,
                                            idcard_front_image: JSON.parse(res.data).data.url,
                                            idcard_front_image_url: JSON.parse(res.data).data.fullurl
                                        })
                                    } else {
                                        that.setData({
                                            uploadback: 1,
                                            idcard_back_image: JSON.parse(res.data).data.url,
                                            idcard_back_image_url: JSON.parse(res.data).data.fullurl
                                        })
                                    }
                                } else {
                                    wx.showToast({
                                        title: JSON.parse(res.data).msg,
                                        icon: 'none',
                                        duration: 3000
                                    })
                                    return;
                                }
                            },
                            fail: res => {
                                console.log(res)
                            }
                        })
                    })
                    wx.hideLoading(); //隐藏loading提示框
                }
            }
        });

    },
	
	applyMsg(){
		 var that = this;
		
		wx.requestSubscribeMessage({
		  tmplIds: [
			'q9Js-vQrnKFfxtsIYMrYF6CQgNNsPITiZtcznzk8P-M',
		    'WCOeBpOwto_yU4ZM-hUmQePvbfY_lxKyaFK5Yi7nzao',		   
			'SOnJPXow5f0XddOr1jQ-3wdd6V1SifOHJMdQtPbJNo0'
		  ],
		  success: (res) => {
			  console.log(res)
		    that.apply(that);
		  },
		  fail: (res) => {
			    console.log(res)
		    that.apply(that);
		  },
		})
	},
    apply(that) {
	
        if (!that.data.contact_name) {
            wx.showToast({
                title: '请输入姓名',
                icon: 'none'
            })
            return false;
        }
        if (!that.data.contact_tel) {
            wx.showToast({
                title: '请输入手机号码',
                icon: 'none'
            })
            return false;
        }
        let reg = /^1[0-9]{10}$/
        if (!reg.test(that.data.contact_tel)) {
            wx.showToast({
                title: '请输入正确手机号码',
                icon: 'none'
            })
            return false;
        }

        if (!that.data.addr) {
            wx.showToast({
                title: '请选择服务地址',
                icon: 'none'
            })
            return false;
        }
        if (!that.data.addr_detail) {
            wx.showToast({
                title: '请输入详细地址',
                icon: 'none'
            })
            return false;
        }

        if (that.data.sevice_category_id.length == 0) {
            wx.showToast({
                title: '请选择服务类型',
                icon: 'none'
            })
            return false;
        }

        if (that.data.tagIds.length == 0) {
            wx.showToast({
                title: '请选择服务标签',
                icon: 'none'
            })
            return false;
        }

        if (!that.data.desc) {
            wx.showToast({
                title: '请输入个人描述',
                icon: 'none'
            })
            return false;
        }

        if (!that.data.idcard_front_image) {
            wx.showToast({
                title: '请上传身份证正面照片',
                icon: 'none'
            })
            return false;
        }
        if (!that.data.idcard_back_image) {
            wx.showToast({
                title: '请上传身份证背面照片',
                icon: 'none'
            })
            return false;
        }
let cityName = wx.getStorageSync('cityName');

        let param = {
            scoure: 'wxapp',
            token: that.data.token,
            contact_name: that.data.contact_name,
            contact_tel: that.data.contact_tel,
            addr: that.data.addr,
            addr_detail: that.data.addr_detail,
            lat: that.data.lat,
            lng: that.data.lng,
            desc: that.data.desc,
            service_category_id: that.data.sevice_category_id,
            service_tag_ids: that.data.tagIds,
            idcard_front_image: that.data.idcard_front_image,
            idcard_back_image: that.data.idcard_back_image,
            extra_image: that.data.picList,
            images: that.data.picLists,
            pay_money: that.data.deposit,
			group_id:2,
            type:2,
			pants_size:that.data.kztag,
			clothing_size:that.data.yftag,
			hat_size:'帽子',
			waistcoat_size:that.data.mjtag,
			citytxt:cityName

        }
        wx.showNavigationBarLoading(); //在当前页面显示导航条加载动画
        request.request(url.workerapply, param, url.REQUEST_METHOD_POST).then((res) => {
            wx.hideNavigationBarLoading(); //在当前页面隐藏导航条加载动画
            wx.showToast({
                title: res.data.msg,
                icon: "none"
            });

            if (res.data.code == 1) {
                //直接支付成功
                var config = JSON.parse(res.data.data.wxconfig);
                console.log("获取成功", JSON.parse(res.data.data.wxconfig));
                wx.requestPayment({
                  'timeStamp': config.timestamp,
                  'nonceStr': config.nonceStr,
                  'package': config.package,
                  'signType': config.signType,
                  'paySign': config.paySign,
                  'success': function (res2) {
                    console.log("成功", res2)
                    wx.showToast({
                      title: '支付成功 等待平台审核',
                      icon: 'success'
                    })
                     // wx.navigateTo({
                     //   url: 'pages/user_end/index/index',
                     // })
					setTimeout(function () {
					    wx.navigateTo({
					      url: '/pages/user_end/index/index'
					    })
					}, 1500)
                    if (res2.errMsg == 'requestPayment:ok') {
                      wx.showToast({
                        title: '支付成功 等待平台审核',
                        icon: 'success'
                      })
               
                      setTimeout(function () {
                        wx.navigateTo({
                          url: '/pages/user_end/index/index'
                        })
                    }, 1500)

                      return false;
                    }
                  },
                  'fail': function (res2) {
                    that.goMine();
                    return false;
                  },
                  'complete': function (res2) {}
                })
              } else {
                wx.showToast({
                  title: res.data.msg,
                  icon: 'none',
                  duration: 2000
                })
              }
            })


        
    }
})